#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct {
	char **p_result;
	int count;
} ExpRes;

int main(){
	char *str="..aaa.bbb.ccc.ddd.";
	char *del=".";
	char **output;
	char *pstr;
	int dcount=0;
	int i= 0;
	size_t csize=0;
	ExpRes rvals;
	pstr=str;

	if (strlen(str) <= strlen(del))
	{
		printf("WTF");
		return 1;
	}

	//mindfuck
	for (i=0; *(pstr+i); *(pstr+i)=='.' ? i++ : pstr++);
	dcount=++i;
	pstr=str;
	i=0;

	printf("Oddelovacov: %d\n",dcount-1);
	printf("Poli bude: %d\n",dcount);

	output=(char**)malloc(dcount*sizeof(char));

	csize = strcspn(pstr, del);

	*(output+i)=(char*)malloc(csize*sizeof(char));
	*(output+i)=strncpy(*(output+i), pstr, csize);
	printf("%d: %d <= %s",i,(int)csize,*(output+i));
	pstr += csize+1;

	if (**(output+i) == NULL) printf(" NULL");
	printf("\n");

	i++;

	for (;i<dcount;i++){

		csize = strcspn(pstr, del);
		*(output+i)=(char*)malloc(csize*sizeof(char));
		*(output+i)=strncpy(*(output+i), pstr, csize);
		printf("%d: %d <= %s",i,(int)csize,*(output+i));
		pstr += csize+1;
		if (**(output+i) == '\0') printf(" NULA");
		if (**(output+i) == NULL) printf(" NULL");
		printf("\n");

	}

	rvals.p_result = output;
	rvals.count = dcount;

	printf("Test: %s\n", *(rvals.p_result+dcount/2));
	printf("Test: %d\n", dcount);

return 0;
};
